package chuangyi.com.org.ViewModel;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.databinding.Bindable;
import android.view.View;
import android.widget.Button;

import chuangyi.com.org.DOMIHome.BR;
import chuangyi.com.org.DOMIHome.HomeActivity;
import chuangyi.com.org.DOMIHome.ParagraphEditor;
import chuangyi.com.org.DOMIHome.PopupActivity;
import chuangyi.com.org.DOMIHome.R;
import chuangyi.com.org.DOMIHome.Utils.WebApi;
import chuangyi.com.org.DOMIHome.adapter.BindingListItem;

/**
 * Created by zxh on 16/12/6.
 */

public class ParagraphItem extends BindingListItem {
    public static final int IMAGE_PARAGRAPH = 0;
    public static final int TEXT_PARAGRAPH = 1;
    private Integer id;
    private int contentType;
    private String content;
    private boolean allowEdit;
    private ParagraphEditor parent;

    @Bindable
    public boolean isAllowEdit() {
        return allowEdit;
    }

    public void setAllowEdit(boolean allowEdit) {
        this.allowEdit = allowEdit;
        if(allowEdit){
            if(contentType == IMAGE_PARAGRAPH){
                setLayout(R.layout.i_edit_image_paragraph);
            }else{
                setLayout(R.layout.i_edit_text_paragraph);
            }
        }else{
            if(contentType == IMAGE_PARAGRAPH){
                setLayout(R.layout.i_image_paragraph);
            }else{
                setLayout(R.layout.i_text_paragraph);
            }
        }
        notifyPropertyChanged(BR.allowEdit);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public ParagraphEditor getParent() {
        return parent;
    }

    public void setParent(ParagraphEditor parent) {
        this.parent = parent;
    }

    @Bindable
    public int getContentType() {
        return contentType;
    }

    @Bindable
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
        notifyPropertyChanged(BR.content);
    }

    public ParagraphItem(Context context, int contentType) {
        super(context, contentType == IMAGE_PARAGRAPH ? R.layout.i_image_paragraph : R.layout.i_text_paragraph);
        this.contentType = contentType;
    }
    /**
     * 点击删除章节/图片
     *
     * @param view
     */
    public void onClickRemoveParagraph(View view) {
        parent.removeParagraph(this);
    }

    public void onClickUpdate(View view) {
        parent.updateParagraph(this);
    }

    public void onClickMoveUp(View view){
        parent.moveUpParagraph(this);
    }

    public void onClickMoveDown(View view){
        parent.moveDownParagraph(this);
    }
}
